import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.中等题.最小栈
 */

class MinStack {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> minStack = new Stack<>();

    public MinStack() {

    }

    public void push(int val) {
        stack1.push(val);
        if(minStack.empty()) {
            minStack.push(val);
        } else if(getMin() >= val) {
            minStack.push(val);
        }
    }

    public void pop() {
        if(stack1.peek().equals(minStack.peek())) {
            stack1.pop();
            minStack.pop();
        } else {
            stack1.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}

public class Test {
}
